@extends('admin.base')
@section('content')
    <meta name="csrf-token" content="{{ csrf_token() }}">

    <div class="layuimini-main">
        <form class="layui-form" action="" onsubmit="return false">
            <div class="layui-form-item">
                <label class="layui-form-label">金蝶名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="jin_customer_name"   placeholder="金蝶客户名称" lay-verify="required" autocomplete="off" class="layui-input" lay-verify="required">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">金蝶编码</label>
                <div class="layui-input-inline">
                    <input type="text" autocomplete="off"  name="jin_customer_code"   placeholder="金蝶编码" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">药天下编码</label>
                <div class="layui-input-inline">
                    <input type="text" autocomplete="off" name="yao_supplier_code"  placeholder="药天下客户编码" autocomplete="off" class="layui-input">
                </div>
            </div>


            <div class="layui-form-item">
                <label class="layui-form-label">类别</label>
                <div class="layui-input-inline">
                    <select name="type" lay-verify="required">
                            <option value="" selected>请选择</option>
                            <option value="1" selected>内部</option>
                            <option value="2" selected>外部</option>
                            <option value="0" selected>其他</option>


                    </select>
                </div>

            </div>

            <div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="submit_reset">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
        @endsection

        @section('script')
            @can('tag.manage')
                <script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
                <script>

            layui.use(['form', 'table','upload','element',], function () {
                var $ = layui.jquery,
                    form = layui.form,
                    table = layui.table,
                    upload = layui.upload;
                form.verify({
                    title: function (value, item) {
                        if (value.length < 5) {
                            return '标题至少得5个字符啊';
                        }
                    }, fname: function (value) {
                        if (value.length < 4) {
                            return '请输入至少4位的用户名';
                        }
                    }, contact: function (value) {
                        if (value.length < 4) {
                            return '内容请输入至少4个字符';
                        }
                    }
                    , phone: [/^1[3|4|5|7|8]\d{9}$/, '手机必须11位，只能是数字！']
                    , email: [/^[a-z0-9._%-]+@([a-z0-9-]+\.)+[a-z]{2,4}$|^1[3|4|5|7|8]\d{9}$/, '邮箱格式不对']
                });

                // 监听搜索操作
                form.on('submit(data-search-btn)', function (data) {
                    var result = JSON.stringify(data.field);
                    layer.alert(result, {
                        title: '最终的搜索信息'
                    });

                    //执行搜索重载
                    table.reload('currentTableId', {
                        page: {
                            curr: 1
                        }
                        , where: {
                            searchParams: result
                        }
                    }, 'data');

                    return false;
                });



                /**
                 * toolbar监听事件
                 */
                table.on('toolbar(currentTableFilter)', function (obj) {
                    if (obj.event === 'add') {  // 监听添加操作
                        var index = layer.open({
                            title: '添加用户',
                            type: 2,
                            shade: 0.2,
                            maxmin:true,
                            shadeClose: true,
                            area: ['100%', '100%'],
                            content: '../page/table/add.html',
                        });
                        $(window).on("resize", function () {
                            layer.full(index);
                        });
                    } else if (obj.event === 'delete') {  // 监听删除操作
                        var checkStatus = table.checkStatus('currentTableId')
                            , data = checkStatus.data;
                        layer.alert(JSON.stringify(data));
                    }
                });

                //监听表格复选框选择
                table.on('checkbox(currentTableFilter)', function (obj) {
                    console.log(obj)
                });

                table.on('tool(currentTableFilter)', function (obj) {
                    var data = obj.data;
                    if (obj.event === 'edit') {

                        var index = layer.open({
                            title: '编辑用户',
                            type: 2,
                            shade: 0.2,
                            maxmin:true,
                            shadeClose: true,
                            area: ['100%', '100%'],
                            content: '../page/table/edit.html',
                        });
                        $(window).on("resize", function () {
                            layer.full(index);
                        });
                        return false;
                    } else if (obj.event === 'delete') {
                        layer.confirm('真的删除行么', function (index) {
                            obj.del();
                            layer.close(index);
                        });
                    }
                });

                // 进行登录操作
                form.on('submit(submit_reset)', function (data) {
                    data = data.field;
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        type: "post",
                        url: "{{ route('admin.tag.customer.save') }}",
                        data:data,
                        dataType: "json",
                        success: function (arg) {
                            if (arg.code == 0) {
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(index);//关闭当前页
                                window.parent.location.reload();
                                window.location.href = '';
                            } else {
                                layer.alert(arg.errmsg);
                            }
                        },
                    });
                    return false;
                });
            });
        </script>

    @endcan
@endsection
